package com.xiaode.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

/**
 * 设置跨域支持
 */
public class AccessAllowInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		
		
		inv.getController().getResponse().addHeader("Access-Control-Allow-Origin", "*");
		inv.getController().getResponse().addHeader("Access-Control-Allow-Headers","X-Requested-With,token");
		
		
		// 增加跨域支持响应头
		String method = inv.getController().getRequest().getMethod();
        if ("OPTIONS".equals(method)) {
            inv.getController().renderText("");
        } else {
            inv.invoke();
        }
		
	}

}
